﻿Public Class Dcolor

    Public Shared Function SeleccionarXEstado(ByVal descEmpresa As String) As List(Of Ecolor)
        Dim colores As List(Of Ecolor) = Nothing 'Es una coleccion de lista tipado (vendedor)

        Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings(descEmpresa).ConnectionString)
            Using cmd As New SqlCommand("usp_color_selXEstado", cn)
                cmd.CommandType = CommandType.StoredProcedure
                Try
                    cn.Open()
                    Using dr As SqlDataReader = cmd.ExecuteReader(CommandBehavior.SingleResult Or CommandBehavior.CloseConnection)
                        If dr.HasRows Then
                            colores = New List(Of Ecolor)
                            Dim color As Ecolor = Nothing 'tipo 
                            Do While dr.Read
                                color = New Ecolor( _
                                    dr.GetInt32(dr.GetOrdinal("idColor")), _
                                    dr.GetString(dr.GetOrdinal("descColor")), _
                                    dr.GetString(dr.GetOrdinal("estado")), _
                                    dr.GetInt32(dr.GetOrdinal("idUsuario")))
                                colores.Add(color)
                            Loop
                            dr.Close()
                        End If
                    End Using
                Catch ex As Exception
                    Throw
                End Try
            End Using
        End Using

        Return colores
    End Function
   
  
    Public Shared Function Eliminar(ByVal descEmpresa As String, ByVal color As Ecolor) As Boolean
        Dim resultado As Boolean = False

        Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings(descEmpresa).ConnectionString)
            Using cmd As New SqlCommand("usp_color_del", cn)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.Add("@idcolor", SqlDbType.Int).Value = color.idcolor
                cmd.Parameters.Add("@idUsuario", SqlDbType.Int).Value = color.idUsuario
                Try
                    cn.Open()
                    cmd.ExecuteNonQuery()
                    resultado = True
                Catch ex As Exception
                    Throw
                End Try
            End Using
        End Using

        Return resultado
    End Function

End Class
